package com.ruoyi.whzj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whzj.domain.WhPointspackage;
import com.ruoyi.whzj.service.IWhPointspackageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分套餐Controller
 * 
 * @author ruoyi
 * @date 2020-11-03
 */
@Controller
@RequestMapping("/whzj/pointspackage")
public class WhPointspackageController extends BaseController
{
    private String prefix = "whzj/pointspackage";

    @Autowired
    private IWhPointspackageService whPointspackageService;

    @RequiresPermissions("whzj:pointspackage:view")
    @GetMapping()
    public String pointspackage()
    {
        return prefix + "/pointspackage";
    }

    /**
     * 查询积分套餐列表
     */
    @RequiresPermissions("whzj:pointspackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhPointspackage whPointspackage)
    {
        startPage();
        List<WhPointspackage> list = whPointspackageService.selectWhPointspackageList(whPointspackage);
        return getDataTable(list);
    }

    /**
     * 导出积分套餐列表
     */
    @RequiresPermissions("whzj:pointspackage:export")
    @Log(title = "积分套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhPointspackage whPointspackage)
    {
        List<WhPointspackage> list = whPointspackageService.selectWhPointspackageList(whPointspackage);
        ExcelUtil<WhPointspackage> util = new ExcelUtil<WhPointspackage>(WhPointspackage.class);
        return util.exportExcel(list, "pointspackage");
    }

    /**
     * 新增积分套餐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存积分套餐
     */
    @RequiresPermissions("whzj:pointspackage:add")
    @Log(title = "积分套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhPointspackage whPointspackage)
    {
        whPointspackage.setStatus("启用");
        return toAjax(whPointspackageService.insertWhPointspackage(whPointspackage));
    }

    /**
     * 启用
     */
    @RequiresPermissions("whzj:pointspackage:add")
    @Log(title = "启用", businessType = BusinessType.INSERT)
    @PostMapping("/beginPackage")
    @ResponseBody
    public AjaxResult beginPackage(String id)
    {
        WhPointspackage whPointspackage = new WhPointspackage();
        whPointspackage.setId(id);
        whPointspackage.setStatus("启用");
        return toAjax(whPointspackageService.updateWhPointspackage(whPointspackage));
    }

    /**
     * 停用
     */
    @RequiresPermissions("whzj:pointspackage:add")
    @Log(title = "停用", businessType = BusinessType.INSERT)
    @PostMapping("/stopPackage")
    @ResponseBody
    public AjaxResult stopPackage(String id)
    {
        WhPointspackage whPointspackage = new WhPointspackage();
        whPointspackage.setId(id);
        whPointspackage.setStatus("停用");
        return toAjax(whPointspackageService.updateWhPointspackage(whPointspackage));
    }

    /**
     * 修改积分套餐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhPointspackage whPointspackage = whPointspackageService.selectWhPointspackageById(id);
        mmap.put("whPointspackage", whPointspackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存积分套餐
     */
    @RequiresPermissions("whzj:pointspackage:edit")
    @Log(title = "积分套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhPointspackage whPointspackage)
    {
        return toAjax(whPointspackageService.updateWhPointspackage(whPointspackage));
    }

    /**
     * 删除积分套餐
     */
    @RequiresPermissions("whzj:pointspackage:remove")
    @Log(title = "积分套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whPointspackageService.deleteWhPointspackageByIds(ids));
    }
}
